#include "pvm/pvmapi.h"
#include "lib/pvmsystem.h"
#include "lib/pvmvoicesource.h"
#include "lib/decoders/speex/pvmvoicespeex.h"
#include "lib/decoders/speex/pvmvoicesourcespeex.h"
#include "lib/decoders/speex/pvmspeexincludes.h"

#include "lib/memory/pvmmemory.h"

PVMVoiceSourceSpeex::PVMVoiceSourceSpeex(IPvmInStream* stream)
{
	this->stream = stream;
	streamIsUsed = false;
}

PVMVoiceSourceSpeex::~PVMVoiceSourceSpeex()
{
	if(stream!=NULL)
	{
		stream->Close();
		stream = NULL;
	}
}

IPVMVoice* PVMVoiceSourceSpeex::CreateVoice(pvm_int /*samplesPerSecond*/, pvm_int /*bitsPerSample*/, pvm_int /*chanelsNum*/)
{
	if(stream==NULL)
		return NULL;
	PVMVoiceSpeex* voice = NULL;
	if(streamIsUsed)
	{
		voice = PVMVoiceSpeex::Create(stream, true, NULL);
	}
	else
	{
		stream->Seek(0, EPVM_SEEK_BEGIN);
		voice = PVMVoiceSpeex::Create(stream, false, &streamIsUsed);
	}

	return voice;
}

void PVMVoiceSourceSpeex::Destroy()
{
	delete( this);
}

pvm_int PVMVoiceSourceSpeex::GetLengthMS()
{
	return -1;
}

pvm_bool PVMVoiceSourceSpeex::GetOption(const pvm_char* /*optionName*/, void* /*optionVal*/, pvm_uint32* /*optionSize*/)
{
	return false;
}

pvm_bool PVMVoiceSourceSpeex::SetOption(const pvm_char* /*optionName*/, void* /*optionVal*/, pvm_uint32 /*optionSize*/)
{
	return false;
}

